var express = require('express');
var db = require('../../../tools/database')
var router = express.Router();
var util = require('../../../tools/util')

// 提交商品信息
// 错误处理标准化 √√
router.use(function (req, res, next) {
	util.jwtVerify(req, res, (decoded) => {
		form = JSON.parse(req.body.formData)
		file_hw_ratio = req.body.file_hw_ratio
		let sql =
			`Insert into Items (ItemName, ItemPrice, ItemDescription, ItemOldNewRate, 
		 CoverFileName, DeliverByPost, DeliverByFace, DeliverNoNeed, Remarks, UserName, CoverFileHWRatio)
		 values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
		let options =
			[form.itemName, form.itemPrice, form.itemDescription, form.itemOldNewRate, form.coverFileName,
				form.hasOwnProperty("deliverByPost"),
				form.hasOwnProperty("deliverByFace"),
				form.hasOwnProperty("deliverNoNeed"),
				form.remarks, decoded.userName, file_hw_ratio]
		db.queryRespond(sql, options, res)
	})


});

module.exports = router;